//
//  ViewController.swift
//  DemoUI
//  标签栏控制器
//  Created by 白瑾浩 on 2022/1/8.
//

import UIKit

class TabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
    
        //去掉导航栏
        self.navigationController?.isNavigationBarHidden = false
        
        tabBar.isTranslucent = false
        
        
        //可以在构造函数中设置相关配置
        addChildVC(childVC: HomeViewController(), title: "首页", norimage: "bird1", selectedImg: "bird2")
        addChildVC(childVC: NewsViewController(), title: "咨询", norimage: "bird3", selectedImg: "bird4")
        addChildVC(childVC: UserViewController(), title: "个人中心", norimage: "bird5", selectedImg: "bird6")
           
        // Do any additional setup after loading the view.
    }
    
    func addChildVC(childVC: UIViewController, title: String, norimage: String,selectedImg:String) {

        tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.red], for: .highlighted)
        var img = UIImage(named: norimage)
        img = img?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)

        var selectedImg = UIImage(named:selectedImg)
        selectedImg = selectedImg?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)

        childVC.tabBarItem.image = img
        childVC.tabBarItem.selectedImage = selectedImg
        childVC.title = title

        let nav = UINavigationController(rootViewController: childVC)
        addChild(nav)

    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
